package cz.vutbr.fit.xzemko01.tfmcbs.diagram.providers;

import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gmf.runtime.common.core.service.AbstractProvider;
import org.eclipse.gmf.runtime.common.core.service.IOperation;
import org.eclipse.gmf.runtime.common.ui.services.parser.GetParserOperation;
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
import org.eclipse.gmf.runtime.common.ui.services.parser.IParserProvider;
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserService;
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
import org.eclipse.gmf.runtime.emf.ui.services.parser.ParserHintAdapter;
import org.eclipse.gmf.runtime.notation.View;

import cz.vutbr.fit.xzemko01.tfmcbs.diagram.edit.parts.ArtifactNameEditPart;
import cz.vutbr.fit.xzemko01.tfmcbs.diagram.edit.parts.ArtifactStereotypeEditPart;
import cz.vutbr.fit.xzemko01.tfmcbs.diagram.edit.parts.CompositeComponentName2EditPart;
import cz.vutbr.fit.xzemko01.tfmcbs.diagram.edit.parts.CompositeComponentNameEditPart;
import cz.vutbr.fit.xzemko01.tfmcbs.diagram.edit.parts.CompositeComponentStereotype2EditPart;
import cz.vutbr.fit.xzemko01.tfmcbs.diagram.edit.parts.CompositeComponentStereotypeEditPart;
import cz.vutbr.fit.xzemko01.tfmcbs.diagram.edit.parts.DependencyNameEditPart;
import cz.vutbr.fit.xzemko01.tfmcbs.diagram.edit.parts.DependencyStereotypeEditPart;
import cz.vutbr.fit.xzemko01.tfmcbs.diagram.edit.parts.GeneralizationNameEditPart;
import cz.vutbr.fit.xzemko01.tfmcbs.diagram.edit.parts.InterfaceName2EditPart;
import cz.vutbr.fit.xzemko01.tfmcbs.diagram.edit.parts.InterfaceNameEditPart;
import cz.vutbr.fit.xzemko01.tfmcbs.diagram.edit.parts.ManifestationNameEditPart;
import cz.vutbr.fit.xzemko01.tfmcbs.diagram.edit.parts.ProvidingPortNameEditPart;
import cz.vutbr.fit.xzemko01.tfmcbs.diagram.edit.parts.RealizationNameEditPart;
import cz.vutbr.fit.xzemko01.tfmcbs.diagram.edit.parts.RequiringPortNameEditPart;
import cz.vutbr.fit.xzemko01.tfmcbs.diagram.edit.parts.SimpleComponentName2EditPart;
import cz.vutbr.fit.xzemko01.tfmcbs.diagram.edit.parts.SimpleComponentNameEditPart;
import cz.vutbr.fit.xzemko01.tfmcbs.diagram.edit.parts.SimpleComponentStereotype2EditPart;
import cz.vutbr.fit.xzemko01.tfmcbs.diagram.edit.parts.SimpleComponentStereotypeEditPart;
import cz.vutbr.fit.xzemko01.tfmcbs.diagram.edit.parts.UsageNameEditPart;
import cz.vutbr.fit.xzemko01.tfmcbs.diagram.parsers.MessageFormatParser;
import cz.vutbr.fit.xzemko01.tfmcbs.diagram.part.ComponentBasedSystemVisualIDRegistry;
import cz.vutbr.fit.xzemko01.tfmcbs.model.meta.TfmcbsPackage;

/**
 * @generated
 */
public class ComponentBasedSystemParserProvider extends AbstractProvider
		implements IParserProvider {

	/**
	 * @generated
	 */
	private IParser simpleComponentName_5001Parser;

	/**
	 * @generated
	 */
	private IParser getSimpleComponentName_5001Parser() {
		if (simpleComponentName_5001Parser == null) {
			EAttribute[] features = new EAttribute[] { TfmcbsPackage.eINSTANCE
					.getElement_Name() };
			MessageFormatParser parser = new MessageFormatParser(features);
			simpleComponentName_5001Parser = parser;
		}
		return simpleComponentName_5001Parser;
	}

	/**
	 * @generated
	 */
	private IParser simpleComponentStereotype_5002Parser;

	/**
	 * @generated
	 */
	private IParser getSimpleComponentStereotype_5002Parser() {
		if (simpleComponentStereotype_5002Parser == null) {
			EAttribute[] features = new EAttribute[] { TfmcbsPackage.eINSTANCE
					.getComponent_Stereotype() };
			MessageFormatParser parser = new MessageFormatParser(features);
			parser.setViewPattern("<<{0}>>"); //$NON-NLS-1$
			parser.setEditorPattern("<<{0}>>"); //$NON-NLS-1$
			parser.setEditPattern("<<{0}>>"); //$NON-NLS-1$
			simpleComponentStereotype_5002Parser = parser;
		}
		return simpleComponentStereotype_5002Parser;
	}

	/**
	 * @generated
	 */
	private IParser compositeComponentName_5012Parser;

	/**
	 * @generated
	 */
	private IParser getCompositeComponentName_5012Parser() {
		if (compositeComponentName_5012Parser == null) {
			EAttribute[] features = new EAttribute[] { TfmcbsPackage.eINSTANCE
					.getElement_Name() };
			MessageFormatParser parser = new MessageFormatParser(features);
			compositeComponentName_5012Parser = parser;
		}
		return compositeComponentName_5012Parser;
	}

	/**
	 * @generated
	 */
	private IParser compositeComponentStereotype_5013Parser;

	/**
	 * @generated
	 */
	private IParser getCompositeComponentStereotype_5013Parser() {
		if (compositeComponentStereotype_5013Parser == null) {
			EAttribute[] features = new EAttribute[] { TfmcbsPackage.eINSTANCE
					.getComponent_Stereotype() };
			MessageFormatParser parser = new MessageFormatParser(features);
			parser.setViewPattern("<<{0}>>"); //$NON-NLS-1$
			parser.setEditorPattern("<<{0}>>"); //$NON-NLS-1$
			parser.setEditPattern("<<{0}>>"); //$NON-NLS-1$
			compositeComponentStereotype_5013Parser = parser;
		}
		return compositeComponentStereotype_5013Parser;
	}

	/**
	 * @generated
	 */
	private IParser artifactName_5014Parser;

	/**
	 * @generated
	 */
	private IParser getArtifactName_5014Parser() {
		if (artifactName_5014Parser == null) {
			EAttribute[] features = new EAttribute[] { TfmcbsPackage.eINSTANCE
					.getElement_Name() };
			MessageFormatParser parser = new MessageFormatParser(features);
			artifactName_5014Parser = parser;
		}
		return artifactName_5014Parser;
	}

	/**
	 * @generated
	 */
	private IParser artifactStereotype_5015Parser;

	/**
	 * @generated
	 */
	private IParser getArtifactStereotype_5015Parser() {
		if (artifactStereotype_5015Parser == null) {
			EAttribute[] features = new EAttribute[] { TfmcbsPackage.eINSTANCE
					.getArtifact_Stereotype() };
			MessageFormatParser parser = new MessageFormatParser(features);
			parser.setViewPattern("<<{0}>>"); //$NON-NLS-1$
			parser.setEditorPattern("<<{0}>>"); //$NON-NLS-1$
			parser.setEditPattern("<<{0}>>"); //$NON-NLS-1$
			artifactStereotype_5015Parser = parser;
		}
		return artifactStereotype_5015Parser;
	}

	/**
	 * @generated
	 */
	private IParser interfaceName_5016Parser;

	/**
	 * @generated
	 */
	private IParser getInterfaceName_5016Parser() {
		if (interfaceName_5016Parser == null) {
			EAttribute[] features = new EAttribute[] { TfmcbsPackage.eINSTANCE
					.getElement_Name() };
			MessageFormatParser parser = new MessageFormatParser(features);
			interfaceName_5016Parser = parser;
		}
		return interfaceName_5016Parser;
	}

	/**
	 * @generated
	 */
	private IParser simpleComponentName_5003Parser;

	/**
	 * @generated
	 */
	private IParser getSimpleComponentName_5003Parser() {
		if (simpleComponentName_5003Parser == null) {
			EAttribute[] features = new EAttribute[] { TfmcbsPackage.eINSTANCE
					.getElement_Name() };
			MessageFormatParser parser = new MessageFormatParser(features);
			simpleComponentName_5003Parser = parser;
		}
		return simpleComponentName_5003Parser;
	}

	/**
	 * @generated
	 */
	private IParser simpleComponentStereotype_5004Parser;

	/**
	 * @generated
	 */
	private IParser getSimpleComponentStereotype_5004Parser() {
		if (simpleComponentStereotype_5004Parser == null) {
			EAttribute[] features = new EAttribute[] { TfmcbsPackage.eINSTANCE
					.getComponent_Stereotype() };
			MessageFormatParser parser = new MessageFormatParser(features);
			parser.setViewPattern("<<{0}>>"); //$NON-NLS-1$
			parser.setEditorPattern("<<{0}>>"); //$NON-NLS-1$
			parser.setEditPattern("<<{0}>>"); //$NON-NLS-1$
			simpleComponentStereotype_5004Parser = parser;
		}
		return simpleComponentStereotype_5004Parser;
	}

	/**
	 * @generated
	 */
	private IParser compositeComponentName_5010Parser;

	/**
	 * @generated
	 */
	private IParser getCompositeComponentName_5010Parser() {
		if (compositeComponentName_5010Parser == null) {
			EAttribute[] features = new EAttribute[] { TfmcbsPackage.eINSTANCE
					.getElement_Name() };
			MessageFormatParser parser = new MessageFormatParser(features);
			compositeComponentName_5010Parser = parser;
		}
		return compositeComponentName_5010Parser;
	}

	/**
	 * @generated
	 */
	private IParser compositeComponentStereotype_5011Parser;

	/**
	 * @generated
	 */
	private IParser getCompositeComponentStereotype_5011Parser() {
		if (compositeComponentStereotype_5011Parser == null) {
			EAttribute[] features = new EAttribute[] { TfmcbsPackage.eINSTANCE
					.getComponent_Stereotype() };
			MessageFormatParser parser = new MessageFormatParser(features);
			parser.setViewPattern("<<{0}>>"); //$NON-NLS-1$
			parser.setEditorPattern("<<{0}>>"); //$NON-NLS-1$
			parser.setEditPattern("<<{0}>>"); //$NON-NLS-1$
			compositeComponentStereotype_5011Parser = parser;
		}
		return compositeComponentStereotype_5011Parser;
	}

	/**
	 * @generated
	 */
	private IParser interfaceName_5005Parser;

	/**
	 * @generated
	 */
	private IParser getInterfaceName_5005Parser() {
		if (interfaceName_5005Parser == null) {
			EAttribute[] features = new EAttribute[] { TfmcbsPackage.eINSTANCE
					.getElement_Name() };
			MessageFormatParser parser = new MessageFormatParser(features);
			interfaceName_5005Parser = parser;
		}
		return interfaceName_5005Parser;
	}

	/**
	 * @generated
	 */
	private IParser providingPortName_5006Parser;

	/**
	 * @generated
	 */
	private IParser getProvidingPortName_5006Parser() {
		if (providingPortName_5006Parser == null) {
			EAttribute[] features = new EAttribute[] { TfmcbsPackage.eINSTANCE
					.getPort_Name() };
			MessageFormatParser parser = new MessageFormatParser(features);
			providingPortName_5006Parser = parser;
		}
		return providingPortName_5006Parser;
	}

	/**
	 * @generated
	 */
	private IParser requiringPortName_5008Parser;

	/**
	 * @generated
	 */
	private IParser getRequiringPortName_5008Parser() {
		if (requiringPortName_5008Parser == null) {
			EAttribute[] features = new EAttribute[] { TfmcbsPackage.eINSTANCE
					.getPort_Name() };
			MessageFormatParser parser = new MessageFormatParser(features);
			requiringPortName_5008Parser = parser;
		}
		return requiringPortName_5008Parser;
	}

	/**
	 * @generated
	 */
	private IParser dependencyName_6001Parser;

	/**
	 * @generated
	 */
	private IParser getDependencyName_6001Parser() {
		if (dependencyName_6001Parser == null) {
			EAttribute[] features = new EAttribute[] { TfmcbsPackage.eINSTANCE
					.getElement_Name() };
			MessageFormatParser parser = new MessageFormatParser(features);
			dependencyName_6001Parser = parser;
		}
		return dependencyName_6001Parser;
	}

	/**
	 * @generated
	 */
	private IParser dependencyStereotype_6002Parser;

	/**
	 * @generated
	 */
	private IParser getDependencyStereotype_6002Parser() {
		if (dependencyStereotype_6002Parser == null) {
			EAttribute[] features = new EAttribute[] { TfmcbsPackage.eINSTANCE
					.getDependency_Stereotype() };
			MessageFormatParser parser = new MessageFormatParser(features);
			parser.setViewPattern("<<{0}>>"); //$NON-NLS-1$
			parser.setEditorPattern("<<{0}>>"); //$NON-NLS-1$
			parser.setEditPattern("<<{0}>>"); //$NON-NLS-1$
			dependencyStereotype_6002Parser = parser;
		}
		return dependencyStereotype_6002Parser;
	}

	/**
	 * @generated
	 */
	private IParser manifestationName_6003Parser;

	/**
	 * @generated
	 */
	private IParser getManifestationName_6003Parser() {
		if (manifestationName_6003Parser == null) {
			EAttribute[] features = new EAttribute[] { TfmcbsPackage.eINSTANCE
					.getElement_Name() };
			MessageFormatParser parser = new MessageFormatParser(features);
			manifestationName_6003Parser = parser;
		}
		return manifestationName_6003Parser;
	}

	/**
	 * @generated
	 */
	private IParser realizationName_6005Parser;

	/**
	 * @generated
	 */
	private IParser getRealizationName_6005Parser() {
		if (realizationName_6005Parser == null) {
			EAttribute[] features = new EAttribute[] { TfmcbsPackage.eINSTANCE
					.getElement_Name() };
			MessageFormatParser parser = new MessageFormatParser(features);
			realizationName_6005Parser = parser;
		}
		return realizationName_6005Parser;
	}

	/**
	 * @generated
	 */
	private IParser usageName_6006Parser;

	/**
	 * @generated
	 */
	private IParser getUsageName_6006Parser() {
		if (usageName_6006Parser == null) {
			EAttribute[] features = new EAttribute[] { TfmcbsPackage.eINSTANCE
					.getElement_Name() };
			MessageFormatParser parser = new MessageFormatParser(features);
			usageName_6006Parser = parser;
		}
		return usageName_6006Parser;
	}

	/**
	 * @generated
	 */
	private IParser generalizationName_6007Parser;

	/**
	 * @generated
	 */
	private IParser getGeneralizationName_6007Parser() {
		if (generalizationName_6007Parser == null) {
			EAttribute[] features = new EAttribute[] { TfmcbsPackage.eINSTANCE
					.getElement_Name() };
			MessageFormatParser parser = new MessageFormatParser(features);
			generalizationName_6007Parser = parser;
		}
		return generalizationName_6007Parser;
	}

	/**
	 * @generated
	 */
	protected IParser getParser(int visualID) {
		switch (visualID) {
		case SimpleComponentNameEditPart.VISUAL_ID:
			return getSimpleComponentName_5001Parser();
		case SimpleComponentStereotypeEditPart.VISUAL_ID:
			return getSimpleComponentStereotype_5002Parser();
		case CompositeComponentNameEditPart.VISUAL_ID:
			return getCompositeComponentName_5012Parser();
		case CompositeComponentStereotypeEditPart.VISUAL_ID:
			return getCompositeComponentStereotype_5013Parser();
		case ArtifactNameEditPart.VISUAL_ID:
			return getArtifactName_5014Parser();
		case ArtifactStereotypeEditPart.VISUAL_ID:
			return getArtifactStereotype_5015Parser();
		case InterfaceNameEditPart.VISUAL_ID:
			return getInterfaceName_5016Parser();
		case SimpleComponentName2EditPart.VISUAL_ID:
			return getSimpleComponentName_5003Parser();
		case SimpleComponentStereotype2EditPart.VISUAL_ID:
			return getSimpleComponentStereotype_5004Parser();
		case CompositeComponentName2EditPart.VISUAL_ID:
			return getCompositeComponentName_5010Parser();
		case CompositeComponentStereotype2EditPart.VISUAL_ID:
			return getCompositeComponentStereotype_5011Parser();
		case InterfaceName2EditPart.VISUAL_ID:
			return getInterfaceName_5005Parser();
		case ProvidingPortNameEditPart.VISUAL_ID:
			return getProvidingPortName_5006Parser();
		case RequiringPortNameEditPart.VISUAL_ID:
			return getRequiringPortName_5008Parser();
		case DependencyNameEditPart.VISUAL_ID:
			return getDependencyName_6001Parser();
		case DependencyStereotypeEditPart.VISUAL_ID:
			return getDependencyStereotype_6002Parser();
		case ManifestationNameEditPart.VISUAL_ID:
			return getManifestationName_6003Parser();
		case RealizationNameEditPart.VISUAL_ID:
			return getRealizationName_6005Parser();
		case UsageNameEditPart.VISUAL_ID:
			return getUsageName_6006Parser();
		case GeneralizationNameEditPart.VISUAL_ID:
			return getGeneralizationName_6007Parser();
		}
		return null;
	}

	/**
	 * Utility method that consults ParserService
	 * @generated
	 */
	public static IParser getParser(IElementType type, EObject object,
			String parserHint) {
		return ParserService.getInstance().getParser(
				new HintAdapter(type, object, parserHint));
	}

	/**
	 * @generated
	 */
	public IParser getParser(IAdaptable hint) {
		String vid = (String) hint.getAdapter(String.class);
		if (vid != null) {
			return getParser(ComponentBasedSystemVisualIDRegistry
					.getVisualID(vid));
		}
		View view = (View) hint.getAdapter(View.class);
		if (view != null) {
			return getParser(ComponentBasedSystemVisualIDRegistry
					.getVisualID(view));
		}
		return null;
	}

	/**
	 * @generated
	 */
	public boolean provides(IOperation operation) {
		if (operation instanceof GetParserOperation) {
			IAdaptable hint = ((GetParserOperation) operation).getHint();
			if (ComponentBasedSystemElementTypes.getElement(hint) == null) {
				return false;
			}
			return getParser(hint) != null;
		}
		return false;
	}

	/**
	 * @generated
	 */
	private static class HintAdapter extends ParserHintAdapter {

		/**
		 * @generated
		 */
		private final IElementType elementType;

		/**
		 * @generated
		 */
		public HintAdapter(IElementType type, EObject object, String parserHint) {
			super(object, parserHint);
			assert type != null;
			elementType = type;
		}

		/**
		 * @generated
		 */
		public Object getAdapter(Class adapter) {
			if (IElementType.class.equals(adapter)) {
				return elementType;
			}
			return super.getAdapter(adapter);
		}
	}

}
